package
{
	public class RenderObject
	{
		public var renderIndex:int = 0;
		public var renderI:int = 0;
		public var renderJ:int = 0;
		public var renderE:int = 0;
		public var renderS:int = 0;
		public var renderID:int = 0;
		
		public var renderParent:RenderObject = null;
		private var renderChildren:Object = null;
		public var renderChildrenArray:Array = null;
		public var renderObject:Object = null;
		
		public function addChild( o:RenderObject ):void
		{
			if ( renderChildren[ o.renderIndex ] )
			{
				for ( var i:int = 0 ; i < renderChildrenArray.length ; i++ )
				{
					if ( renderChildrenArray[i] == o )
					{
						renderChildrenArray.splice( i , 1 );
					}
				}
				
				renderChildrenArray.push( o );
				return;
			}
			
			if ( o.renderParent )
			{
				o.renderParent.removeChild( o );
			}
			
			o.renderParent = this;
			renderChildren[ o.renderIndex ] = o;
			
			renderChildrenArray.push( o );
		}
		
		public function removeChild( o:RenderObject ):void
		{
			o.renderParent = null;
			
			renderChildren[ o.renderIndex ] = null;
			delete renderChildren[ o.renderIndex ];
			
			for ( var i:int = 0 ; i < renderChildrenArray.length ; i++ )
			{
				if ( renderChildrenArray[i] == o )
				{
					renderChildrenArray.splice( i , 1 );
					return;
				}
			}
		}
		
		public function clear():void
		{
			for each( var obj:RenderObject in renderChildren )
			{
				obj.renderParent = null;
				obj.renderObject = null;
				
				obj.clear();
				delete renderChildren[ obj.renderIndex ];
			}
			
			renderChildrenArray.length = 0;
		}
		
		public function RenderObject()
		{
			renderChildren = new Object();
			renderChildrenArray = new Array();
		}
	}
}
